
class WanAndroidResp<T> {
  final int code;
  final String msg;
  final T? data;

  WanAndroidResp({
    required this.code,
    required this.msg,
    required this.data,
  });

  factory WanAndroidResp.fromJson(
      Map<String, dynamic> json,
      T Function(Object? json) fromJsonT,
      ) {
    final rawData = json['data'];
    return WanAndroidResp<T>(
      code: (json['errorCode'] as num).toInt(),
      msg: json['errorMsg'] as String,
      data: rawData == null ? null : fromJsonT(rawData),
    );
  }

  Map<String, dynamic> toJson(Object Function(T value) toJsonT) {
    return <String, dynamic>{
      'errorCode': code,
      'errorMsg': msg,
      if (data != null) 'data': toJsonT(data as T), // 显式断言为非 null 再传入函数
    };
  }
}